package wechat.rcv.cosuming

import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
class WXRequestTree {
	static Logger logger = Logger::getLogger("WXRequestTree")
	
	private IMsgConsuming consumObj;
	private RequestObj ro;
//	@Autowired
//	private EventSubscribeConsuming eventSubscribeConsuming
//	
//	@Autowired
//	private EventScanConsuming eventScanConsuming
//	
	@Autowired
	private TxtMsgConsuming txtMsgConsuming
	@Autowired
	private EventClickConsuming eventClickConsuming
		
	@Autowired
	private EventUnSubscribeConsuming eventUnSubscribeConsuming
	@Autowired
	private EventSubscribeConsuming eventSubscribeConsuming
//	@Autowired
////	private EventAckConsuming eventAckConsuming
	def IMsgConsuming getHandler(RequestObj r){
		this.ro = r
		logger.info('EventAckConsuming ro.msgType = '+ ro.msgType)
		switch (ro.msgType){
			case 'event':{
				switch (ro.event){
					case 'subscribe':{
						return eventSubscribeConsuming=>[setRequestObj(ro)]
					}
					case 'unsubscribe':{
						return eventUnSubscribeConsuming=>[setRequestObj(ro)]
					}
//					case 'SCAN':{
//						return eventScanConsuming=>[setRequestObj(ro)]
//					}
//					case 'TEMPLATESENDJOBFINISH':{
//						return eventAckConsuming=>[setRequestObj(ro)]
//					}
//					case 'VIEW':{
//						return eventAckConsuming=>[
//							ro.status = 'success'
//							setRequestObj(ro)
//						]
//					}
					case 'click':{
						logger.info('EventClickConsuming ro.event = '+ ro.event)
						return new EventClickConsuming()=>[setRequestObj(ro)]
					}										
				}
			}
//			case 'text':{
//				return txtMsgConsuming=>[setRequestObj(ro)]
//			}
		}
//		return eventClickConsuming=>[setRequestObj(ro)]
	}
//	def EventSubscribeConsuming getSub(){
//		eventSubscribeConsuming=>[setRequestObj(this.ro)]
//	}
//	def IMsgConsuming getHandleObject(String xmlmsg) throws Exception{
//		IMsgConsuming ret = null;
//		String msgType = RequestParser.getMsgType(xmlmsg);
//		if (msgType.equalsIgnoreCase("text")) {
//			ret = new TxtMsgConsuming(xmlmsg);
//		} else if (msgType.equalsIgnoreCase("event")) {
//			if (RequestParser.getElementByTag(xmlmsg, "Event").equalsIgnoreCase("click"))
//				ret = new EventClickConsuming(xmlmsg);
//		}
//		if (ret==null){
//			logger.info("msgType is " + msgType);
//			throw new Exception();
//		}
//		return ret;
//	}	
}